<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/13
 * Time: 22:45
 */
include "../classes/logincheck.php";
include '../classes/conn.php';
if(islogin()!='teacher_login'){
    die('error');
}
if(isset($_POST['nums'])&&isset($_POST['names'])) {

    $nums = $_POST['nums'];
    $names = $_POST['names'];
    $class = $_POST['class'];
    $sec = $_POST['sec'];
    for ($i = 0; $i < count($nums); $i++) {
        if ($nums[$i] != "") {
//        查询小节序号是否存在
            $query = "select num from subsection where num='{$nums[$i]}' and section='{$sec}' and class='{$class}' and teacher='{$_SESSION['t_num']}'";
            $res = mysql_query($query);
            if (mysql_num_rows($res)) {
                echo 'sub_exist';
            } else {
//        插入数据
                $query = "insert into subsection (num,name,section,class,teacher) values ('{$nums[$i]}','{$names[$i]}','{$sec}','{$class}','{$_SESSION['t_num']}')";
                mysql_query($query);
            }
        }
    }
}
